cmake_minimum_required(VERSION 3.12)
project(fishbot_behavior_tree)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

find_package(ament_cmake REQUIRED)
find_package(behaviortree_cpp REQUIRED)
find_package(rclcpp REQUIRED)
find_package(pluginlib REQUIRED)
find_package(tl_expected REQUIRED)
find_package(generate_parameter_library REQUIRED)
find_package(fishbot_behavior_interface REQUIRED)
find_package(rclcpp_action REQUIRED)

set(
  THIS_PACKAGE_INCLUDE_DEPENDS
  behaviortree_cpp
  rclcpp
  pluginlib
  tl_expected
  generate_parameter_library
  fishbot_behavior_interface
  rclcpp_action
)

add_library(fishbot_behavior_tree 
  SHARED
  src/async_behavior_base.cpp
)
target_include_directories(fishbot_behavior_tree PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)
ament_target_dependencies(fishbot_behavior_tree ${THIS_PACKAGE_INCLUDE_DEPENDS})

# fishbot_bt_loader
generate_parameter_library(
  behaviors_loader_parameters # cmake target name for the parameter library
  src/behaviors_loader_parameters.yaml # path to input yaml file
)
add_executable(fishbot_bt_loader src/fishbot_bt_loader.cpp)
target_include_directories(fishbot_bt_loader PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include/papjia_behavior_tree>
)
target_link_libraries(fishbot_bt_loader PUBLIC
  behaviors_loader_parameters
)
ament_target_dependencies(fishbot_bt_loader PUBLIC  ${THIS_PACKAGE_INCLUDE_DEPENDS} )

install (
  TARGETS fishbot_bt_loader
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

# Install libraries
install(
  TARGETS ${PROJECT_NAME}
  EXPORT export_${PROJECT_NAME}
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION bin
)

install(
  DIRECTORY include/
  DESTINATION include
)

install(
  DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}
)

ament_export_include_directories(
  include
)
ament_export_libraries(
  ${PROJECT_NAME}
)
ament_export_targets(
  export_${PROJECT_NAME}
)
ament_export_dependencies(${THIS_PACKAGE_INCLUDE_DEPENDS})
ament_package()